package org.hadoop;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.IOException;

import org.apache.hadoop.fs.FileStatus;

public class Demo01AccessHDFS {

    public static void main(String[] args) {
        System.setProperty("HADOOP_USER_NAME", "hadoop");
        Configuration config = new Configuration();
        config.set("fs.defaultFS", "hdfs://192.168.56.102:8020");//注意修改IP
        FileSystem fs = null;
        try {
            fs = FileSystem.get(config);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        FileStatus[] stas = null;
        try {
            stas = fs.listStatus(new Path("/"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        for (FileStatus f : stas) {
            System.out.println(f.getPermission().toString() + " "
                    + f.getPath().toString());
        }
        try {
            fs.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
